home *** CD-ROM | disk | FTP | other *** search
/ Visual Cafe 3 / Visual Cafe 3.ISO / Vcafe / JFC.bin / JDesktopPane.java < prev    next >
Text File  |  1998-06-30  |  8KB  |  247 lines

  1. /*
  2.  * @(#)JDesktopPane.java    1.17 98/03/13
  3.  *
  4.  * Copyright (c) 1997 Sun Microsystems, Inc. All Rights Reserved.
  5.  *
  6.  * This software is the confidential and proprietary information of Sun
  7.  * Microsystems, Inc. ("Confidential Information").  You shall not
  8.  * disclose such Confidential Information and shall use it only in
  9.  * accordance with the terms of the license agreement you entered into
  10.  * with Sun.
  11.  *
  12.  * SUN MAKES NO REPRESENTATIONS OR WARRANTIES ABOUT THE SUITABILITY OF THE
  13.  * SOFTWARE, EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
  14.  * IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
  15.  * PURPOSE, OR NON-INFRINGEMENT. SUN SHALL NOT BE LIABLE FOR ANY DAMAGES
  16.  * SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR DISTRIBUTING
  17.  * THIS SOFTWARE OR ITS DERIVATIVES.
  18.  *
  19.  */
  20.  
  21. package com.sun.java.swing;
  22.  
  23. import java.util.Vector;
  24. import com.sun.java.swing.plaf.*;
  25. import com.sun.java.accessibility.*;
  26.  
  27. /**
  28.  * A container used to create a multiple-document interface or a virtual desktop. 
  29.  * You create JInternalFrame objects and add them to the JDesktopPane. 
  30.  * JDesktopPane extends JLayeredPane to manage the potentially overlapping internal frames. It also 
  31.  * maintains a reference to an instance of DesktopManager that is set by the UI 
  32.  * class for the current Look and Feel (L&F). 
  33.  * <p>
  34.  * This class is normally used as the parent of JInternalFrames to provide a
  35.  * pluggable DesktopManager object to the JInternalFrames. The installUI of the 
  36.  * L&F specific implementation is responsible for setting the desktopManager 
  37.  * variable appropriately. When the parent of a JInternalFrame is a JDesktopPane, 
  38.  * it should delegate most of its behavior to the desktopManager (closing, resizing,
  39.  * etc).
  40.  * <p>
  41.  * For the keyboard keys used by this component in the standard Look and
  42.  * Feel (L&F) renditions, see the
  43.  * <a href="doc-files/Key-Index.html#JDesktopPane">JDesktopPane</a> key assignments.
  44.  * <p>
  45.  * Warning: serialized objects of this class will not be compatible with
  46.  * future swing releases.  The current serialization support is appropriate 
  47.  * for short term storage or RMI between Swing1.0 applications.  It will
  48.  * not be possible to load serialized Swing1.0 objects with future releases
  49.  * of Swing.  The JDK1.2 release of Swing will be the compatibility
  50.  * baseline for the serialized form of Swing objects.
  51.  *
  52.  * @see JInternalFrame
  53.  * @see JInternalFrame.JDesktopIcon
  54.  * @see DesktopManager
  55.  *
  56.  * @version 1.17 03/13/98
  57.  * @author David Kloba
  58.  */
  59. public class JDesktopPane extends JLayeredPane implements Accessible
  60. {
  61.     DesktopManager desktopManager;
  62.  
  63.     /** 
  64.      * Creates a new JDesktopPane.
  65.      */
  66.     public JDesktopPane() {
  67.         updateUI();
  68.     }
  69.  
  70.     /**
  71.      * Returns the L&F object that renders this component.
  72.      *
  73.      * @return the DesktopPaneUI object that renders this component
  74.      */
  75.     public DesktopPaneUI getUI() {
  76.         return (DesktopPaneUI)ui;
  77.     }
  78.  
  79.     /**
  80.      * Sets the L&F object that renders this component.
  81.      *
  82.      * @param ui  the DesktopPaneUI L&F object
  83.      * @see UIDefaults#getUI
  84.      */
  85.     public void setUI(DesktopPaneUI ui) {
  86.         super.setUI(ui);
  87.     }
  88.  
  89.     /** 
  90.      * Returns the DesktopManger that handles desktop-specific UI actions.
  91.      *
  92.      * @param d the DesktopManager currently in use 
  93.      */
  94.     public DesktopManager getDesktopManager() {
  95.         return desktopManager;
  96.     }
  97.  
  98.     /**
  99.      * Sets the DesktopManger that will handle desktop-specific UI actions.
  100.      *
  101.      * @param d the DesktopManager to use 
  102.      */
  103.     public void setDesktopManager(DesktopManager d) {
  104.         desktopManager = d;
  105.     }
  106.  
  107.     /**
  108.      * Notification from the UIManager that the L&F has changed. 
  109.      * Replaces the current UI object with the latest version from the 
  110.      * UIManager.
  111.      *
  112.      * @see JComponent#updateUI
  113.      */
  114.     public void updateUI() {
  115.         setUI((DesktopPaneUI)UIManager.getUI(this));
  116.     }
  117.  
  118.  
  119.     /**
  120.      * Returns the name of the L&F class that renders this component.
  121.      *
  122.      * @return "DesktopPaneUI"
  123.      * @see JComponent#getUIClassID
  124.      * @see UIDefaults#getUI
  125.      */
  126.     public String getUIClassID() {
  127.         return "DesktopPaneUI";
  128.     }
  129.  
  130.     /** 
  131.      * Returns all JInternalFrames currently displayed in the
  132.      * desktop. Returns iconified frames as well as expanded frames.
  133.      *
  134.      * @return an array of JInternalFrame objects
  135.      */
  136.     public JInternalFrame[] getAllFrames() {
  137.         int i, count;
  138.         JInternalFrame[] results;
  139.         Vector vResults = new Vector(10);
  140.         Object next, tmp;
  141.  
  142.         count = getComponentCount();
  143.         for(i = 0; i < count; i++) {
  144.             next = getComponent(i);
  145.             if(next instanceof JInternalFrame)
  146.                 vResults.addElement(next);
  147.             else if(next instanceof JInternalFrame.JDesktopIcon)  {
  148.                 tmp = ((JInternalFrame.JDesktopIcon)next).getInternalFrame();
  149.                 if(tmp != null)
  150.                     vResults.addElement(tmp);
  151.             }
  152.         }
  153.  
  154.         results = new JInternalFrame[vResults.size()];
  155.         vResults.copyInto(results);
  156.  
  157.         return results;
  158.     }
  159.  
  160.     /**
  161.      * Returns all JInternalFrames currently displayed in the
  162.      * specified layer of the desktop. Returns iconified frames as well
  163.      * expanded frames.
  164.      *
  165.      * @param layer  an int specifying the desktop layer
  166.      * @return an array of JInternalFrame objects
  167.      * @see JLayeredPane
  168.      */
  169.     public JInternalFrame[] getAllFramesInLayer(int layer) {
  170.         int i, count;
  171.         JInternalFrame[] results;
  172.         Vector vResults = new Vector(10);
  173.         Object next, tmp;
  174.  
  175.         count = getComponentCount();
  176.         for(i = 0; i < count; i++) {
  177.             next = getComponent(i);
  178.             if(next instanceof JInternalFrame)
  179.                 if(((JInternalFrame)next).getLayer() == layer)
  180.                     vResults.addElement(next);
  181.             else if(next instanceof JInternalFrame.JDesktopIcon)  {
  182.                 tmp = ((JInternalFrame.JDesktopIcon)next).getInternalFrame();
  183.                 if(tmp != null && ((JInternalFrame)tmp).getLayer() == layer)
  184.                     vResults.addElement(tmp);
  185.             }
  186.         }
  187.  
  188.         results = new JInternalFrame[vResults.size()];
  189.         vResults.copyInto(results);
  190.  
  191.         return results;
  192.     }
  193.  
  194.     /**
  195.      * Returns true to indicate that this component paints every pixel
  196.      * in its range. (In other words, it does not have a transparent
  197.      * background or foreground.)
  198.      *
  199.      * @return true
  200.      * @see JComponent#isOpaque
  201.      */
  202.     public boolean isOpaque() {
  203.         return true;
  204.     }
  205.  
  206. /////////////////
  207. // Accessibility support
  208. ////////////////
  209.  
  210.     /**
  211.      * Get the AccessibleContext associated with this JComponent
  212.      *
  213.      * @return the AccessibleContext of this JComponent
  214.      */
  215.     public AccessibleContext getAccessibleContext() {
  216.         if (accessibleContext == null) {
  217.             accessibleContext = new AccessibleJDesktopPane();
  218.         }
  219.         return accessibleContext;
  220.     }
  221.  
  222.     /**
  223.      * The class used to obtain the accessible role for this object.
  224.      * <p>
  225.      * Warning: serialized objects of this class will not be compatible with
  226.      * future swing releases.  The current serialization support is appropriate
  227.      * for short term storage or RMI between Swing1.0 applications.  It will
  228.      * not be possible to load serialized Swing1.0 objects with future releases
  229.      * of Swing.  The JDK1.2 release of Swing will be the compatibility
  230.      * baseline for the serialized form of Swing objects.
  231.      */
  232.     protected class AccessibleJDesktopPane extends AccessibleJComponent {
  233.  
  234.         /**
  235.          * Get the role of this object.
  236.          *
  237.          * @return an instance of AccessibleRole describing the role of the 
  238.          * object
  239.          * @see AccessibleRole
  240.          */
  241.         public AccessibleRole getAccessibleRole() {
  242.             return AccessibleRole.DESKTOP_PANE;
  243.         }
  244.     }
  245. }
  246.  
  247.